﻿Ext.define('page.Configuration.Mod', {
    extend: 'Kwan.ex.ModuleInstance',
    getForm: function () {
        var form = Ext.create('Ext.form.Panel', {
            id: 'fp_Configuration',
            layout: 'vbox',
            region: 'center',
            waitMsgTarget: true,
            autoScroll: true,
            bodyPadding: 10,
            defaults: { labelWidth: 300 },
            items: [
                {
                    xtype: 'fieldset',
                    width: 700,
                    layout: { columns: 2, type: 'table' },
                    title: '基本设置',
                    items: [
                        { xtype: 'textfield', labelAlign: 'right', width: 200, fieldLabel: '默认押金', name: 'Deposit' },
                        { xtype: 'label', labelAlign: 'right', padding: 5, style: 'color:#999;', width: 200, text: '元' },
                        { xtype: 'textfield', labelAlign: 'right', width: 200, fieldLabel: '超时价', name: 'OutTimePrice' },
                        { xtype: 'label', labelAlign: 'right', padding: 5, style: 'color:#999;', width: 200, text: '元/时' },
                        { xtype: 'checkboxgroup', labelAlign: 'right', width: 200, fieldLabel: '选项', columns: 1,
                            items: [{ xtype: 'kwanCheckbox', boxLabel: '自动读卡', name: 'AutoReadCard' }, { xtype: 'kwanCheckbox', boxLabel: '自动计费', name: 'AutoCheckOut'}]
                        }
                    ]
                }, {
                    xtype: 'fieldset',
                    width: 700,
                    layout: { columns: 2, type: 'table' },
                    title: '计费设置', flex: 1,
                    items: [
                        { xtype: 'timefield', format: 'H:i:s', labelAlign: 'right', width: 200, minValue: '00:00', maxValue: '12:00', increment: 30, fieldLabel: '客人开房时间在', name: 'NewDayTime' },
                        { xtype: 'label', padding: 5, width: 200, text: '之后按新的一天开始计费' },
                        { xtype: 'timefield', format: 'H:i:s', labelAlign: 'right', width: 200, increment: 30, fieldLabel: '客人开房时间在', name: 'NightTime' },
                        { xtype: 'label', padding: 5, width: 200, text: '之后按夜房费用计费' },
                        { xtype: 'timefield', format: 'H:i:s', labelAlign: 'right', width: 200, minValue: '12:00', maxValue: '17:00', increment: 30, fieldLabel: '客人退房时间在', name: 'AddHourTime' },
                        { xtype: 'label', padding: 5, width: 200, text: '之后自动追加一小时' },
                        { xtype: 'timefield', format: 'H:i:s', labelAlign: 'right', width: 200, minValue: '12:00', maxValue: '17:00', increment: 30, fieldLabel: '客人退房时间在', name: 'AddHalfTime' },
                        { xtype: 'label', padding: 5, width: 200, text: '之后计价天数自动追加半天' },
                        { xtype: 'timefield', format: 'H:i:s', labelAlign: 'right', width: 200, minValue: '12:00', maxValue: '20:00', increment: 30, fieldLabel: '客人退房时间在', name: 'AddDayTime' },
                        { xtype: 'label', padding: 5, width: 200, text: '之后计价天数自动追加一天' },
                        { xtype: 'numberfield', labelAlign: 'right', width: 200, fieldLabel: '客人退房时间在', name: 'DefaultHours' },
                        { xtype: 'label', padding: 5, width: 200, text: '小时内按钟点价收费' },
                        { xtype: 'numberfield', labelAlign: 'right', width: 200, fieldLabel: '以上时限可再宽限', name: 'AllowTime' },
                        { xtype: 'label', padding: 5, width: 200, text: '分钟' }
                    ]
                }
            ],
            dockedItems: [{ xtype: 'toolbar', dock: 'bottom', ui: 'footer',
                items: { scale: 'medium', text: '保存', style: 'margin:1px', icon: "/Admin/style/24Icons/clean.png", width: 80, height: 35,
                    listeners: {
                        scope: this,
                        click: function () {
                            var form = Ext.getCmp('fp_Configuration').form;
                            if (form.isValid()) {
                                var data = Ext.encode(Ext.apply(form.getValues(), { EntityID: 1 }));
                                Ext.Ajax.request({
                                    url: 'facade.axd?s_action=Configuration',
                                    params: { s_method: 'save', data: data, EntityID: 1 },
                                    success: function (response) {
                                        var data = eval('(' + response.responseText + ')');
                                        if (data.success) {
                                            Ext.create('Kwan.ex.PopupWin', {
                                                title: '系统提示',
                                                html: '<div style="font-weight:700;text-align:center">修改成功！</div>'
                                            }).show();
                                        }
                                    }
                                });
                            }
                        }
                    }
                }
            }]
        });
        form.load({ scope: this, url: 'facade.axd?s_action=Configuration&s_method=list' });
        return form;
    },
    run: function () {
        var me = this;
        me.center = me.getForm();
        me.viewport.add([me.center]);
    }
});